package servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;

import dao.UserDao;
import dao.impl.UserDaoImpl;
import entity.User;
import entity.User_Inf;
import service.UserService;
import service.impl.UserServiceImpl;


public class SywUserRegistServlet extends HttpServlet {
	private UserDao ud = new UserDaoImpl();
	private UserService us = new UserServiceImpl();
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setContentType("applition/json;charset=utf-8");
		String sywUserName = request.getParameter("sywUserName");//获取到用户名
		String[] sywPassword = request.getParameterValues("sywPassword");//获取到密码
		String sywSex = request.getParameter("sywSex");//获取性别value
		String sywEmail = request.getParameter("sywEmail");//获取邮箱
		String sywTellPhone = request.getParameter("sywTellPhone");//获取手机号
		/*Date date = new Date();*///调用时间
		/*System.out.println(sywSex);*/
		User user = new User();
		user.setUsername(sywUserName);
		user.setPassword(sywPassword[0]);
		boolean savaUser = us.savaUser(user);
		
		//调用User_Inf实体类
		User_Inf inf = new User_Inf();
		//从request中取到的数据存入到User_Inf中
		inf.setUsername(sywUserName);
		inf.setPhone(sywTellPhone);
		inf.setUser_email(sywEmail);
		inf.setGender(sywSex);
		inf.setModified_time(new Date());
		//将存入inf的数据传入数据库中
		boolean otherInfo = us.saveUserOtherInfo(inf);
		/*System.out.println(otherInfo);*/
		if (otherInfo) {
			request.getRequestDispatcher("Login.jsp").forward(request, response);
		}
	}
	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
